public class AddOne {
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        for (int i = n - 1; i >= 0; i --) {
            if(digits[i] != 9) {
                digits[i] = digits[i] + 1;
                for (int j = i+1; j < n; j ++) {
                    digits[j] = 0;
                }
                return digits;
            }
        }
        int[] ans = new int[n + 1];
        ans[0] = 1;
        return ans;
}